<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${cuinfo.cname}</title>
<% request.setAttribute("menu", 1); %>
<%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
<link rel="stylesheet" href="<%=basePath%>css/global.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="<%=basePath%>css/tab.css" media="all" />
<link rel="stylesheet" href="<%=basePath%>css/system.css" media="all">

<script type="text/javascript" src="<%=basePath%>js/qualify/zizhisel.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jobsel/job.js"></script>

<style type="text/css">
.enteringhide { display: block;}
.qymc p { display: block; border-bottom: 1px solid #cccccc; text-align: left;}

/* 增行弹窗 */
.addlxjl,.addyyjl,.addlxrtc,.addxqtc,.addwjtc { display:none; }
.tc_customercontactsdiv,.tc_customercategorydiv,.tc_customerfilediv { margin: 10px 0 0 0; }
.customtext {height: 30px; width: 265px; font-size: 16px; border: 1px solid #e6e6e6;}
.tc_customercategorydiv .customselect { height: 30px; width: 80px; font-size: 16px;}
.tc_btndiv { margin-top: 30px; text-align: center; }
.tc_btndiv .tc_savebtn { width: 100px; height: 40px; text-align: center; border: 0;
			background-color: #a48ad4; cursor: pointer; border-radius: 2px; font-size: 18px; color: rgb(255, 255, 255);}
.tc_customercategorydiv .categoryselect .layui-input-inline { width: 268px; }

/* 隐藏显示 */
.hideadd { display: none; }
.showadd { display: block; }

/* 必填前的红点 */
.layui-form-label i { color:red; padding-right: 3px; }



</style>
</head>
<body>

<div class="admin-tab TM-tab admin-entering">
    <form class="layui-form" action="" id="enterform">
    <div class="layui-field-box entering-box">
    	<div class="entering">
            <h4>基本信息&nbsp;&nbsp;<button lay-submit="" lay-filter="save"class="layui-btn layui-btn-primary layui-btn-small" data="0">保存</button>
            	<button class="layui-btn layui-btn-primary layui-btn-small refreshbtn" type="button"><i class="layui-icon">&#x1002;</i>刷新</button>
            </h4>
            <table class="site-table table-hover" >
            <tr >
            <td style="padding-top: 10px;">
             <div class="layui-form-item">
                <label class="layui-form-label">资源类型 : </label>
                <div class="layui-input-block"  style="margin-left: 98px;" >  
                    <dic:cf type="3"   inputName="iszj"   name="customer_zj"  value="${cuinfo.iszj!=null?cuinfo.iszj:0}"    />
                </div>  
            </div>
            <div class="form-left" style="width: 33%;">
            <div class="layui-form-item">
                <label class="layui-form-label"><i>*</i><span>姓名 : </span> </label>
                <div class="layui-input-inline qymc">
                	<c:if test="${customerid != null && customerid > 0}">
                		<p>${cuinfo.cname}</p>
                	</c:if>
                	<c:if test="${customerid == 0 || customerid == null }">
                		<input type="text" name="cname" id="cname"   autocomplete="off" class="layui-input">
                	</c:if>
                </div>
            </div>
            <div class="layui-form-item">
         		<label class="layui-form-label"><i>*</i><span>联系电话 : </span></label>
             	<div class="layui-input-inline" style="width: 50%;">
             		<input type="text" name="tel" id="tel" value='${ccon.tel}' autocomplete="off" class="layui-input">
             	</div>
        	</div>
        	<div class="layui-form-item">
            	<label class="layui-form-label"><i>*</i><span>证书专业 : </span></label>
                <div class="layui-input-inline" style="width: 70%;">
                	<input type="text" name="technicalpost" id="technicalpost" value="${cuinfo.technicalpost}" autocomplete="off" class="layui-input">
                </div>
           	</div>
        	<%-- <c:if test="${customerid == 0 || customerid == null }">
	            <div class="layui-form-item">
	                <label class="layui-form-label"><i>*</i><span>拥有证书 : </span></label>
	                <div class="layui-input-inline" style="width: 50%;">
	                	<input name="category" id="category" type="hidden" value='${ccat.category}'>
	                	<input type="text" name="zizhiType1" id="zizhiType1" class="layui-input">
	                </div>
	            </div>
            </c:if> --%>
            <div class="layui-form-item address">
                <label class="layui-form-label">地址 : </label>
                <div class="layui-input-inline" style="width: 50%;">
                	 <input type="text" name="address"  id="address"  value="${cuinfo.address}"  autocomplete="off" class="layui-input">
                    <%-- <select name="province" id="province"  lay-filter="province" class="provinceclass" >
                        <option value="-1" selected>请选择省</option>
                        <c:forEach var="prov" items="${province}" varStatus="p1">
                        	<option value="${prov.id}"  <c:if test="${cuinfo.province==prov.id}">selected</c:if>>${prov.provincename}</option>
                        </c:forEach>
                    </select> --%>
                </div>
               <%--  <div class="layui-input-inline">
                    <select name="city" id="city"  lay-filter="city" value="${cuinfo.city}">
                    	<option value="">请选择市</option>
                    </select>
                </div> --%>
            </div>
            <div class="layui-form-item">
	            <label class="layui-form-label">QQ : </label>
	            <div class="layui-input-inline">
	            	<input type="text" name="qq" id="qq" value='${ccon.qq}' autocomplete="off" class="layui-input">
	            </div>
           	</div>
           	 <div class="layui-form-item">
         		<label class="layui-form-label">微信 : </label>
             	<div class="layui-input-inline">
             		<input type="text" name="webchart" id="webchart" value="${ccon.webchart}" autocomplete="off" class="layui-input">
             	</div>
        	</div>
           	<div class="layui-form-item">
         		<label class="layui-form-label">人才帐号 : </label>
             	<div class="layui-input-inline">
             		<input type="text" name="account" id="account" value="${cuinfo.account}" autocomplete="off" class="layui-input">
             	</div>
        	</div>
        	<div class="layui-form-item">
         		<label class="layui-form-label">聘用密码 : </label>
         		<div class="layui-input-inline ">
	         		<input type="text" name="passwordtwo" id="passwordtwo"   value="${cuinfo.passwordtwo}"   autocomplete="off" class="layui-input">
	            </div>
	            	<label class="layui-form-label">后台密码 : </label>
             	  <div class="layui-input-inline">
             	   				<input type="text" name="password" id="password"    value="${cuinfo.password}"   autocomplete="off" class="layui-input">
             	  </div>  
        	</div>
        </div>
        <div class="form-right" style="width: 40%;">
        	<div class="layui-form-item">
                <label class="layui-form-label"><i></i><span>备用名 : </span> </label>
                <div class="layui-input-inline qymc">
                	<input type="text" name="nickname" id="nickname" value="${cuinfo.nickname}" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label"><i>*</i><span> 录入时间 : </span></label>
                <div class="layui-input-inline qymc">
	                <c:if test="${customerid != null && customerid > 0}">
	                	<p>${cuinfo.createdate.substring(0,10)}</p>
	                </c:if>
	                <c:if test="${customerid == 0 || customerid == null }">
	                    	<input type="text" name="createdate" id="createdate" value='${fn:length(ccat.createdate)>0 ? ccat.createdate.substring(0,10) : ""}' placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
	                </c:if>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">到期时间 : </label>
                <div class="layui-input-inline">
                    <input type="text" name="endtime" id="endtime" readonly="readonly"  value='${cuinfo.endtime.substring(0,10)}' placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})">
                </div>
            </div>
          <%--   <c:if test="${customerid == 0 || customerid == null }">
	           	<div class="layui-form-item">
	            	<label class="layui-form-label">挂证类型 : </label>
	                <div class="layui-input-inline">
	                    <select name="types" id="types">
	                    	<option value="3" <c:if test="${cuinfo.types == 3}">selected</c:if> >不限</option>
	                        <option value="1" <c:if test="${cuinfo.types == 1}">selected</c:if> >初始</option>
	                        <option value="2" <c:if test="${cuinfo.types == 2}">selected</c:if> >转注册</option>
	                    </select>
	                </div>
	           	</div>
           	</c:if> --%>
            <div class="layui-form-item warehouse">
                <label class="layui-form-label">成熟等级 : </label>
                <div class="layui-input-inline">
                
                    <select name="state" id="state">
                    	<c:if test="${cuinfo.state==4 || state == 4}">  <option value="4"  selected >公共资源</option></c:if>
                        <c:if test="${cuinfo.state!=4}">
                           <option value="0" <c:if test="${cuinfo.state==0 || state == 0}">selected</c:if>>最新资源</option> 
                           <option value="1" <c:if test="${cuinfo.state==1 || state == 1}">selected</c:if>>意向不明</option> 
                          <option value="2" <c:if test="${cuinfo.state==2 || state == 2}">selected</c:if>>意向明确</option>
                          <option value="3" <c:if test="${cuinfo.state==3 || state == 3}">selected</c:if>>意向强烈</option>
                          <option value="7" <c:if test="${cuinfo.state==7 || state == 7}">selected</c:if>>合作客户</option> 
                        </c:if> 
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
            	<label class="layui-form-label">身份证号 : </label>
                <div class="layui-input-inline"   style="width: 60%;">
                	<input type="text" name="idcard" id="idcard" value="${cuinfo.idcard}" autocomplete="off" class="layui-input">
                </div>
            </div>
           <div class="layui-form-item warehouse">
	            <label class="layui-form-label">客户来源 : </label>
	            <div class="layui-input-inline">
	                   <select name="source" id="source">
	                       <option value="0">客户来源</option>
	                       <dic:cf type="2" name="customer_source" value="${cuinfo.source}"/>
	                   </select>
	             </div>
             </div>
             <div class="layui-form-item warehouse">
            	<label class="layui-form-label ">客户分类 : </label>
                <div class="layui-input-inline">
                    <select name="level" id="level">
                    	<option value="0" <c:if test="${cuinfo.level == null || cuinfo.level < 1}">selected</c:if>  >客户分类</option>
                    	<option value="1" <c:if test="${cuinfo.level == 1}">selected</c:if> >小客户</option>
                    	<option value="2" <c:if test="${cuinfo.level == 2}">selected</c:if> >普通客户</option>
                    	<option value="3" <c:if test="${cuinfo.level == 3}">selected</c:if> >重点客户</option>
                    	<option value="4" <c:if test="${cuinfo.level == 4}">selected</c:if> >优质客户</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline TM-textarea-block"  style="width: 60%;">
                <textarea placeholder="请输入内容" class="layui-textarea" id="summary" name="summary">${cuinfo.summary}</textarea>
            </div>
        </div>
        <div class="layui-form-item TM-save-item">
            <div class="layui-input-block">
            	<input type="hidden" value="${customerid}" id="id" name="id" >
            	<input type="hidden" value="${type}" id="type" name="type">
            	<input type="hidden" value="${state}" id="states" name="states">
            </div>
        </div>
        </td></tr></table></div></div>
        
    </form>
    
	<!-- 这里现在用showadd和hideadd控制 -->
	<div class="layui-field-box entering-box hideadd <c:if test="${customerid != null && customerid > 0 }"> showadd </c:if>">
		<div class="entering">
            <h4>联系记录 <button class="layui-btn layui-btn-primary layui-btn-small lxjladd" data="4">+添加联系记录</button></h4>
            <table class="site-table table-hover TM-table3">
                <thead> 
                <tr>
                	<th style="width:18%;">跟进人</th>
                    <th style="width:18%">跟进时间</th>
                    <th style="width:64%">跟进内容</th>
                </tr>
                </thead>
                <tbody class="tb_customercontacts lxjlbody">
                <c:forEach var="lxobj" items="${lxpager.resultList}" varStatus="lx">
                		<tr>
                			<td>${lxobj.uname}</td>
	                		<td>${lxobj.updatedate.substring(0,10)} ${lxobj.updatedate.substring(10,16)}</td>
	                		<td>${lxobj.remark}</td>
                		</tr>
                	</c:forEach>
                </tbody>
                	 <tfoot <c:if test="${lxpager.totalPages<2}"> style="display:none"</c:if>>
	                  <tr>
	                  <td colspan="4">
		                   <div class="admin-table-page">
				   				<div id="page" class="page"></div>
							</div> 
					   </td>
	                   </tr>
	                </tfoot> 
               
               
            </table>
            <input type="hidden" name="linetype" id="linetype1" value="1">
        </div>
        <%-- <div class="entering">
            <h4>证书类型&nbsp;&nbsp;<button class="layui-btn layui-btn-primary layui-btn-small addxq" data="2">+添加证书</button></h4>
            <form  class="layui-form" action="" method="post" id="savecustomercategoryform">
                <table class="site-table table-hover TM-table3">
	                <thead>
		                <tr>
		                    <th style="width:108px;">序号</th>
		                    <th style="width:375px;">证书类型</th>
		                    <th style="width:260px;">性质</th>
		                    <th style="width:260x;">用途</th>
		                    <th style="width:170px;">操作</th>
		                </tr>
	                </thead>
                    <tbody class="tb_customercategory">
                    	<c:forEach var="catobj" items="${cuinfo.categoryItem}" varStatus="cat"> 
		                	<tr class="catetr${catobj.id}" data="${catobj.id}">
			                	<td>${cat.index+1}</td>
			                	<td><dic:cf value="${catobj.category}" name="build_category" type="1"/></td>
			                	<td>
				                	<c:if test="${catobj.types == 1}">
				                		初始
				                	</c:if>
				                	<c:if test="${catobj.types == 2}">
				                		转注册
				                	</c:if>
				                	<c:if test="${catobj.types == 3}">
				                		不限
				                	</c:if>
			                	</td>
			                	<td>
			                		<c:if test="${catobj.paperspurpose == 1}">
			                			升资质
			                		</c:if>
			                		<c:if test="${catobj.paperspurpose == 2}">
			                			挂项目
			                		</c:if>
			                		<c:if test="${catobj.paperspurpose == 3}">
			                			动态核查
			                		</c:if>
			                		<c:if test="${catobj.paperspurpose == 0}">
			                			其他
			                		</c:if>
			                	</td>
			                	<td>
			                		<button class='layui-btn layui-btn-primary layui-btn-small updatecustomercategory' type='button'>修改<i class='layui-icon'></i></button>
			                		<button class='layui-btn layui-btn-primary layui-btn-small deletecategory' type='button'>删除<i class='layui-icon'></i></button>
			                	</td>
		                	</tr>
		                </c:forEach>
                    </tbody>
                </table>
            </form>
        </div> --%>
        <div class="entering">
            <h4>预约记录 <button class="layui-btn layui-btn-primary layui-btn-small yyjladd" data="5">+添加预约</button></h4>
            <table class="site-table table-hover TM-table3">
                <thead>
                <tr>
                    <th style="width:145px;">预约时间</th>
                    <th style="width:145px;">预约人</th>
                    <th style="width:145px;">备注</th>
                </tr>
                </thead>
                <tbody class="tb_customercontacts">
                	<c:forEach var="yyobj" items="${yypager.resultList}" varStatus="yy">
                		<tr>
	                		<td>${yyobj.stime.substring(0,10)} ${yyobj.stime.substring(10,16)}</td>
	                		<td>${yyobj.uname}</td>
	                		<td>${yyobj.remark}</td>
                		</tr>
                	</c:forEach>
                </tbody>
            </table>
            <input type="hidden" name="linetype" id="linetype1" value="1">
        </div>
        <div class="entering">
            <h4>相关附件(共 <i>${fn:length(cuinfo.filesItem)}</i> 条) <button class="layui-btn layui-btn-primary layui-btn-small addwj" data="3">+增加文件</button></h4>
            <form action="" method="post" enctype="multipart/form-data" id="customerfileform">
            <table class="site-table table-hover TM-table3">
                <thead>
                <tr>
                    <th style="width:50px;">序号</th>
                    <th style="width:160px;">文件名</th>
                    <th style="width:160px;">文件类别</th>
                    <th style="width:130px;">文件大小</th>
                    <th style="width:120px;">备注</th>
                    <th style="width:140px;">操作</th>
                </tr>
                </thead>
                <tbody class="tb_customerfile">
                <c:forEach var="fileobj" items="${cuinfo.filesItem}" varStatus="file">
                	<tr class="filetr${fileobj.id}" data="${fileobj.id}">
	                    <td>${file.index+1}</td>
	                    <td>${fileobj.filesinfo.name}</td>
	                    <td>${fileobj.type==1?'原件':'扫描件'}</td>
	                    <td>${fileobj.filesinfo.filesize}kb</td>
	                    <td class="fielremark">${fileobj.remark}</td>
	                    <td>
	                    	<%-- <button class="layui-btn layui-btn-primary layui-btn-small detelecustomerfilebtn" type='button' data="${fileobj.id}">删除<i class="layui-icon "></i></button> --%>
	                    	<button class="layui-btn layui-btn-primary layui-btn-small downloadcunstomerfilesbtn" type='button' data="${fileobj.filesinfo.id}">下载<i class="layui-icon"></i></button>
	                    	<c:if test="${fileobj.filesinfo.suffix=='png'||fileobj.filesinfo.suffix=='jpg'||fileobj.filesinfo.suffix=='gif'}">
	                   
	                    <button class="layui-btn layui-btn-primary layui-btn-small downloadcunstomerfilesbtntwo" type='button' data="${fileobj.filesinfo.id}">预览<i class="layui-icon"></i></button>
	                    </c:if>
	                    </td>
                	</tr>
                </c:forEach>
                </tbody>
            </table>
            </form>
        </div>
    </div>
    
    
    <!-- 文件弹窗 -->
    <div class="addwjtc">
    	<div class="tc_customerfilediv">
    		<form class="layui-form" action="" method="post" id="tc_customerfileform" enctype="multipart/form-data">
    			<div class="layui-form-item">
    				<label class="layui-form-label">选择文件 : </label>
    				<div class="layui-input-inline" style="width:70%">
    					<input type="file" id="upfile" name="file" class="layui-input"/>
    				</div>
    			</div>
    			<div class="layui-form-item">
    				<label class="layui-form-label">选择类别 : </label>
    				<div class="layui-input-inline" style="width:70%">
    					<select name="filetype" id="type" class="layui-input layui-unselect">
	                        <option value="1">扫描件（原件在公司）</option>
	                        <option value="2">扫描件</option>
	                	</select>
    				</div>
    			</div>
    			<div class="layui-form-item">
    				<label class="layui-form-label">备注 : </label>
    				<div class="layui-input-inline" style="width:70%">
	                	<input type="text" name="remark" id="fsremarks" class="layui-input">
	                </div>
    			</div>
    			<div class="layui-form-item tc_btndiv">
    				<input type="hidden" value="0" id="customerfileid" name="fileid">
	            </div>
    		</form>
    	</div>
    </div>
    
    <!-- 联系记录弹窗 -->
    <div class="addlxjl">
    	<form class="layui-form" id="tjlxjlForm" action="">
	      <div class="layui-form-item address" style="margin-top:10px">
	            <label class="layui-form-label">联系人： </label>
	            <div class="layui-input-block" style="width:60%">
	                  <select name="contact" id="contact"  lay-filter="contact">
	                    	<option value="">请选择</option>
	                 </select>
	            </div>
	        </div>
		     <div class="layui-form-item layui-form-text">
			    <label class="layui-form-label"><i>*</i><span>备注：</span></label>
			    <div class="layui-input-block" style="width:60%">
			      <textarea id="remark" name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
			        <input name="id" id="jlid" type="hidden" value="0">
			    </div>
			 </div>
	    </form>
    </div>
    
    
    
    <!-- 预约记录弹窗 -->
    <div class="addyyjl">
    	<form action="" method="post" id="bookingform">
			<div class="TM-booking-to" style="padding:10px 20px;">
				<div class="layui-form-item">
					<label class="layui-form-label">预约时间：</label>
					<div class="layui-input-block" style="width:60%">
						<input type="text" name="stime" id="stime" placeholder="YYYY-MM-DD hh:mm:ss" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this, min: laydate.now(0), istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
	    			</div>
    			</div>
    			<div class="layui-form-item">
					<label class="layui-form-label">备注：</label>
				    <div class="layui-input-block" style="width:60%">
				      	<textarea name="remark" id="email-inner" placeholder="请输入内容" class="layui-textarea"></textarea>
				    </div>
			    </div>
				<!-- <textarea name="remark" id="email-inner" cols="60" rows="5" style="width: 606px;"></textarea> -->
				<!-- <div id="bookingbtndiv" style="text-align: center; margin-top: 10px;">
					<input type="button" value="保存" id="savebooking">
					<input type="button" value="取消" id="cancelbooking">
				</div> -->
			</div>
		</form>
    </div>
    
    
</div>

<div class="Mask ZZmask"></div>

<script id="dyjl" type="text/html"> 
{{#  layui.each(d.list, function(index, item){ }} 
       <tr>
	      <td>{{item.uname}}</td>
	      <td>{{item.updatedate.substring(0,10)}} {{item.updatedate.substring(10,16)}}</td>
	      <td>{{#  if(item.remark!=null){ }} {{item.remark}}  {{#  } }} </td>
        </tr> 
{{#  }); }} 
</script>
<script>
    layui.use(['laypage','laytpl','form','laydate'], function() {
        var $ = layui.jquery,
                layer = layui.layer,
                laytpl = layui.laytpl,
                laypage = layui.laypage;
        var form = layui.form();
    	
 /*      var jobselobj=   $("#zizhiType").jobsel({
           	'inputName' : "categorys"
           });
      
      jobselobj.init();
      
      var jobselobj1=   $("#zizhiType1").jobsel({
         	'inputName' : "category"
         }); 
    
    jobselobj1.init();*/
      
  	//分页按钮
    	laypage({
            cont: 'page',
            curr:  '${lxpager.pageNo}'
            ,pages: '${lxpager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) { 
                	$.ajax({
              		type : "post",
              		url : "/customer/customerdynamic",
              		async : false,
              		data : {skipToPage : curr,cusid : '${customerid}'},
              		dataType : "json",
              		success : function(data){
              			 var getTpl = $("#dyjl").html();
  				 laytpl(getTpl).render(data, function(html){
  					  
  					 $(".lxjlbody").html(html);
  					  //view.innerHTML = html;
  					});
              			 
              		}
              	});
                	 
                }
            }
        }); 
      
      
	   var id = $("#province").val();
	   if(id>0){
		   var html = city.getCityByPid(id);
			   $("#city").html(html);
			   var cv =  $("#city").attr("value"); 
			   if(cv>0){
				 $("#city").val(cv); 
			   }
			   //更新渲染  
	    	   form.render(); 
	   }
      
        //省份城市选择
    	form.on('select(province)', function(data){
    		var id = $("#province").val();
    		var html = city.getCityByPid(id);
			$("#city").html(html);
			//更新渲染
	    	form.render('select');
    	});
        
        //监听提交
        form.on('submit(back)', function() {
        	var type = $("#type").val();
        	var state = $("#states").val();
        	var url = "/customer/entman/ty"+type+"_st"+state;
        	window.location.href = url;
         });
        
        
        //验证唯一标识符是否已经存在
    	jQuery.validator.addMethod("checktel", function(value,element) {
    		var iszj = $('input[name="iszj"]:checked').val();
			if(iszj ==1){
				 return true;
		    }
        	var flag = true;
        	value = $.trim(value);
        	var id = $("#id").val();
        	if (value.length > 0) {
        		$.ajax({
            		type : "post",
            		url : "/customer/chaecktelisexist",
            		async : false,
            		data : {phone : value,id : id},
            		dataType : "json",
            		success : function(data){
            			if (id == '' || id == null) {
            				//说明是新增
            				if (data > 0) {
            					flag = false;
            				} else {
            					flag = true;
            				}
            			} else {
            				//说明是修改
            				if (data > 1) {
            					flag = false;
            				}
            			}
            		}
            	});
        	}
            return flag;
        }, "号码已存在");
        
        
        
        //录入客户验证
		$("#enterform").validate({
			
	    	rules: {
	    		cname : {
	    			required:true,
	    			rangelength:[2,20] 
	    		},
	    		city: {
	    			required:true
	    		},
	    		province: {
	    			required:true
	    		},
	    		createdate: {
	    			required:true
	    		},
	    		state: {
	    			required:true
	    		},
	    		phone: {
	    			checktel:true
	    		},
	    		tel: {
	    			required:true,
	    			checktel:true,
	    		},technicalpost:{
	    			required:true
	    		}/* ,
	    		zizhiType1: {
	    			required:true,
	    		}, */
	    	},
	    	messages: {
	    		cname : {
	    			required:"请输入客户姓名",
	    			rangelength:"长度在2-20之间", 
	    		},
	    		city: {
	    			required:"请选择城市",
	    		},
	    		province: {
	    			required:"请选择省份",
	    		},
	    		createdate: {
	    			required:"请选择创建时间",
	    		},
	    		state: {
	    			required:"请选择所在库",
	    		},
	    		phone: {
	    			checktel:"号码已存在",
	    		},
	    		tel: {
	    			required:"请输入联系号码",
	    			checktel:"号码已存在",
	    		},technicalpost:{
	    			required:"请输入证书及专业"
	    		}
	    		/* ,
	    		zizhiType1: {
	    			required:"请选择证书类型",
	    		}, */
	    	},
	    	errorPlacement: function(error, element) {
				layer.tips(error.text(), element, {
					tips: [2,tipColor],
	     		 tipsMore: true
	     		});
	   		}, 
	   	 submitHandler: function(form) {
	   		 
	   		var $form = $(form),
            data = $form.serialize();
	   		$.ajax({
	   			 type : "post",
	   			 url : "/customer/savecustomer",
	   			 data : data,
	   			 dataType : "json",
	   			 async : false,
	   			 success : function(data){
	   				 if (data == 0) {
	   					layer.msg("简历录入失败");
	   				 } else {
	   					layer.msg("简历录入成功");
	   					window.location.href = "/customer/updatecustomer"+data;
					}
	   			 }
	   		 });
	      }
	    });
        
        
        
		//添加文件
        $(document).on("click",".addwj",function(){
        	layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"添加文件",
		  		zIndex: 999,
		  		content: $(".addwjtc"),
		  		area:['50%','350px'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		        	var file = $("#upfile").val();
		        	if (file == null || file == ""){
		        		layer.msg("请选择您要上传的文件");
		        		return false;
		        	} else {
		        		var infoid = $("#id").val();
		        		var url = "/customer/uploadCustomerfilei"+infoid+"_t"+0;
		        		$("#tc_customerfileform").attr("action",url);
		        		layer.msg("文件上传中",function(){
		        			$("#tc_customerfileform").submit();
		        		})
		        	}
		  		}   		
        	});
        });
        
      	
        //点击下载
        	$(".downloadcunstomerfilesbtn").on("click",function(){
        		var id = $(this).attr("data");
        		//window.location.href = "/file/"+id;
        		window.open("/file/"+id,'target','');
        	});

      	//点击下载
        	$(".downloadcunstomerfilesbtntwo").on("click",function(){
        		var id = $(this).attr("data");
        		//window.location.href = "/viewfile/"+id;
        		window.open("/viewfile/"+id,'target','');
        	});
        	
      	
      	//点击删除
      	/* $(".detelecustomerfilebtn").on("click",function(){
      		
      		var id = $(this).attr("data");
      		
      		layer.confirm('是否确认删除', {
      		  	btn: ['确认','取消'] //按钮
      		}, function(){
      			$.ajax({
          			type : "post",
          			url : "/customer/deletefileinfo",
          			data : {id:id},
          			dataType : "json",
          			success : function(data){
          				layer.msg("删除成功",function(){
          					window.location.reload();
          				});
          			}
          		})
      		}, function(){
      			layer.closeAll();
      		});
      		
      	}); */
      	
        //添加需求
        $(document).on("click",".addxq",function(){
        	$("#categoryid").val(0);
        	layer.open({
        		type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"添加证书",
		  		zIndex: 999,
		  		content: $(".addxqtc"),
		  		area:['40%','350px'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			$("#tc_savecustomercategoryform").submit();
		  		}   		
        	});
        });
      
        // 点击保存需求信息
        $("#tc_savecustomercategoryform").validate({
        	rules: {
        		zizhiType : {
	    			required:true,
	    		},
	    	},
	    	messages: {
	    		zizhiType : {
	    			required:"请选择资质类别",
	    		},
	    	},
	    	errorPlacement: function(error, element) {
				layer.tips(error.text(), element, {
					tips: [2,tipColor],
	     		 tipsMore: true
	     		});
	   		}, 
	   	 submitHandler: function(form) {
	  		 
		 	var category = $("#categorys").val();
		 	var categorytext = $("#zizhiType").val();
		 	var types = $("#types").val();
		 	var paperspurpose = $("#paperspurpose").val();
		 	var cusid = $("#id").val();
		 	var categoryid = $("#categoryid").val();
		 	$.ajax({
		 		type : "post",
		 		url : "/customer/savecustomercategory",
		 		data : {id:categoryid,cusid:cusid,category:category,types:types,paperspurpose:paperspurpose},
		 		dataType : "json",
		 		async : false,
		 		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		 		success : function(data){
		 			
		 			if (categoryid != null && categoryid > 0 ) {
		 				//修改
		 				var html = $(".catetr"+categoryid).html();
		 				html += "<tr class='catetr"+ data["id"] +"' data='"+ data["id"] +"'>"
		 				+"<td>"+ $(".tb_customercategory tr").length +"</td>"
	                	+"<td>"+ categorytext +"</td>"
	                	+"<td>"+ data["type"] +"</td>"
	                	+"<td>"+ data["paperspurpose"] +"</td>"
	                	+"<td>"
	                	+"<button class='layui-btn layui-btn-primary layui-btn-small updatecustomercategory' type='button'>修改<i class='layui-icon'></i></button>"
	                	+"<button class='layui-btn layui-btn-primary layui-btn-small deletecategory' type='button'>删除<i class='layui-icon'></i></button>"
	                	+"</td>"
	                	+"</tr>";
	                	$(".catetr"+categoryid).html(html);
		 			} else {
		 				//新增
		 				var html = $(".tb_customercategory").html();
			 			html += "<tr class='catetr"+ data["id"] +"' data='"+ data["id"] +"'>"
			                	+"<td>"+ $(".tb_customercategory tr").length +"</td>"
			                	+"<td>"+ categorytext +"</td>"
			                	+"<td>"+ data["type"] +"</td>"
			                	+"<td>"+ data["paperspurpose"] +"</td>"
			                	+"<td>"
			                	+"<button class='layui-btn layui-btn-primary layui-btn-small updatecustomercategory' type='button'>修改<i class='layui-icon'></i></button>"
			                	+"<button class='layui-btn layui-btn-primary layui-btn-small deletecategory' type='button'>删除<i class='layui-icon'></i></button>"
			                	+"</td>"
			                	+"</tr>";
			            $(".tb_customercategory").html(html);
		 			}
		            layer.closeAll();
		 		}
		 	});
	      }
        	
        });
      	
      //点击弹出联系记录
      	$(".lxjladd").on("click",function(){
      		var cid = $("#id").val();
      		$.ajax({
 		 		type : "post",
 		 		url : "/customer/customerinfoajax1",
 		 		data : {id:cid},
 		 		dataType : "json",
 		 		async : false,
 		 		success : function(data){
 		 			var html ="";
 		 		    var contacts =	data.contactsItem;
 		 		    var cname = data.cname; 
 		 		    if(contacts!=null&&contacts.length>0){
 		 		    	for(var i =0;i<contacts.length;i++){
 		 		    		 html+="<option value='"+contacts[i].id+"'>"+contacts[i].name+"(电话："+contacts[i].phone+")</option>";
 		 		    	} 
 		 		    	$("#contact").html(html);
 		 		    }else{
 		 		    	$("#contact").html("<option value=''>请选择联系人</option>");
 		 		    }
 		 			form.render(); 
 		 			 layer.open({
	                       type:1,
	                       content:$('.addlxjl'),
	                       btn:['确定','取消'],
	                       btnAlign:'c',
	                       shadeClose:true,
	                       title:cname+'添加联系记录',
	                       area:['600px','300px'],
	                       maxWidth:800,
	                       yes: function(layero, index){
		                   		var ccuid = $("#contact").val();
		                       	var remark = $.trim($("#remark").val());
		                       	var cusid = $("#id").val();
		                       	var url = "/customer/updatecustomer"+cusid;
		                       	if (remark == null || remark.length < 1) {
		                       		layer.msg("请输入联系记录");
		                       		return false;
		                       	}
		                       	$.ajax({
		                       		type : "post",
		                       		url : "/customer/addcontactsdynamicinfo",
		                       		data : {ccuid:ccuid,remark:remark,cusid:cusid},
		                       		dataType : "json",
		                       		success : function(data){
		                       			if (data == 1) {
		                       				layer.msg("添加联系记录成功",{time : 700},function(){
		                       					window.location.reload();
		                       				});
		                       			} else {
		                       				layer.msg("添加联系记录失败",{time : 700},function(){
		                       					window.location.reload();
		                       				});
		                       			}
		                       		}
		                       	});
	                       }
 	                 });
 		 		}
 		 	});
      	});
      
      //删除需求
      	$(document).on("click",".deletecategory",function(){
      		var ids = $(this).parent().parent().attr("data");
      		var cusid = $("#id").val();
      		
      		layer.confirm('是否确认删除', {
      		  	btn: ['确认','取消'] //按钮
      		}, function(){
      			$.ajax({
          			type : "post",
          			url : "/customer/deletecustomercategorybyid",
          			data : {id:ids,cusid:cusid},
          			dataType : "json",
          			success : function(data){
          				layer.msg("证书删除成功",{time:700},function(){
    						window.location.reload();
    					});
          			}
          		});
      		}, function(){
      			layer.closeAll();
      		});
      	});
      
      //点击修改categorys
        $(document).on("click",".updatecustomercategory",function(){
        	var ids = $(this).parent().parent().attr("data");
        	$.ajax({
        		type: "post",
        		url: "/customer/getcustomercategory",
        		data: {ids:ids},
        		dataType: "json",
        		success:function(data){
        			$("#categorys").val(data["category"]);
                	$("#types").val(data["type"]);
                	$("#paperspurpose").val(data["paperspurpose"]);
                	$("#remarks").val(data["remark"]);
                	$("#categoryid").val(ids);
                	jobselobj.selData();
                	form.render();
                	layer.open({
              		  	type:1,
        		  		title:"修改证书信息",
        		  		zIndex: 999,
        		  		btn:['确定','取消'],
        	           	btnAlign:'c',
        		  		shadeClose:true,
        		  		content: $(".addxqtc"),
        		  		area:['40%','50%'],
        		  		maxWidth:800,
        		  		yes: function(layero, index){
        		  			$("#tc_savecustomercategoryform").submit();
        		  		}
              		});
        		}
        	})
        });
      
      	//点击弹出预约记录
      	$(".yyjladd").on("click",function(){
      		layer.open({
	   		  	type:1,
	   		  	btn:['确定','取消'],
	           	btnAlign:'c',
	           	shadeClose:true,
		  		title:"添加预约",
		  		zIndex: 999,
		  		content: $(".addyyjl"),
		  		area:['30%','350px'],
		  		maxWidth:800,
		  		yes: function(layero, index){
		  			
		  			var stime = $("#stime").val();
					var remark = $("#email-inner").val();
					var value = $("#id").val();
					var url = "/customer/updatecustomer"+value;
					$.ajax({
						type : "post",
						url : "/customer/bookingcontactsdynamicinfo",
						data : {stime:stime,remark:remark,value:value},
						dataType : "json",
						success : function(data){
							if (data == 0) {
								layer.msg("预约失败，请重试",{time : 700},function(){
									layer.closeAll();
								});
							} else {
								layer.msg("预约成功",{time : 700},function(){
									window.location.href=url;
								});
							}
						}
					});
               }
      		});
      	});
    });
    
  
</script>
</body>

</body>
</html>